//e
#Title[Tv1]
#Text[]
#Image[]
#BGM[]
#Player[FREE]
#PlayLevel[]
#BackGround[]
#ScriptVersion[2]

script_enemy_main {

    // ֐̎荞
    #include_function ".\usershot\lib_usershot.txt"	// ew萔ǂݍ
    #include_function ".\effectdata\Obj_EffectALL.txt"	// GtFNg֐ꊇǂݍ

    // XNvg܂ł̃pX̎擾
    let csd        = GetCurrentScriptDirectory();

    // G摜̃pX
    let imgBoss    = csd ~ "img\ExRumia.png";

    // G̖O摜̃pX
    let ename      = csd ~ "img\ename.png";

    // ʒu̐ݒ
    let xIni       = GetCenterX()  + 1;
    let yIni       = GetClipMinY() + 120;

    // e摜̃pX
    let shotData   = csd ~ "\usershot\data_usershot.txt";

    @Initialize {

	LoadGraphic(imgBoss);
	SetTexture(imgBoss);

	SetLife(400);
	SetTimer(60);
	SetDamageRate(0,0);

	DrawTimer();				// c莞Ԃ̕\
	DrawTimerEx(2);				// c莞Ԃ̕\
	EnemyMarker01();			// Gl~[}[J[̕\
	LifeBar_A_02(0, 0.4, 0.6, true);	// Q[W̕\
	LifeBar_B_02(1, 0.4, 0.2, true);	// Q[W̕\
	LifeBar_B_02(3, 0.2, 0.0, true);	// ԃQ[W̕\

	LifeStockBar(2);			// cXyJ[h̕\
	LifeStock(2,0);				// cXyJ[h̕\
	LifeCircleBar_A(0.4, 0.6, true);	// 1{ڂ̉~Q[W̕\
	LifeCircleBar_B(0.4, 0.2, true);	// 2{ڂ̉~Q[W̕\
	LifeCircleBar_B(0.2, 0.0, true);	// 3{ڂ̉~Q[W̕\
	LifeCircleBar_Marker(0.4);		// 1ڂ̋؂̕\
	LifeCircleBar_Marker(0.8);		// 2ڂ̋؂̕\

	DrawEnemyName(ename,0,16,true);		// G̖O̕\

	MagicCircle(false);
	SetRateScoreSystemEnable(false);
	LoadUserShotData(shotData);
	SetEffectForZeroLife(0, 0, 0);
	SetShotAutoDeleteClip(32, 32, 32, 32);

	MainTask();

    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 32);

	yield;
    }

    @DrawLoop {
	DrawGraphic(GetX, GetY);
    }

    @Finalize {
	//DeleteGraphic(imgBoss);
    }

    // C^XN
    task MainTask {

	yield;

	StandBy();

	Aura1( 8, 64, 64,128);	// I[̕\[1]
	Aura2(60,160, 64, 64);	// I[̕\[2]
	MagicCircleEx2(true);	// @w̕\
	wait(60);

	Shot();

    }

    // ʒuֈړ
    function StandBy {
	SetMovePositionRandom01(416, 464, 5, xIni, yIni, xIni, yIni);
	SetGraphicMove();
	wait(60);
	SetGraphicStop();
	wait(60);
	SetDamageRate(20,0);
	SetGraphicPose();
    }

    // U
    task Shot {

	let way      = 3;			// e
	let long     = 40;			// G̋
	let speed    = 4.00;			// x
	let angle    = rand_int(0,360);		// 1ڂ̊px
	let addangle = 0.00;			// px
	let addspeed = -speed/60;		// x
	let maxspeed = 0.00;			// ōx(Œᑬx)
	let delay    = 12;			// x

	let eff     = dRED01a;			// GtFNg̒萔(ID)
	let graphic = US_BALL_S_A_RED;		// e摜̒萔
	let bomb    = false;			// {ϐ
	let time    = 80;			// RŎ

	let n       = 1;

	loop {
	    loop(120) {
		loop(way) {
		    CreateObjShotC_T02(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, angle, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
		    angle += 360 / way;
		}
		angle += 1.5*n;
		wait(1);
	    }
	    loop(60) {
		loop(way) {
		    CreateObjShotC_T03(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, angle, addangle, addspeed, maxspeed, graphic+5, eff+5, delay, time+rand_int(-50,0), bomb);
		    angle += 360 / way;
		}
		angle = rand_int(0,360);
		wait(2);
	    }
	    n = n*-1;
	}
    }

    // OtBbN̐ݒ
    sub SetGraphicStop  { SetGraphicRect(  0,  0, 64, 64); }
    sub SetGraphicPose  { SetGraphicRect( 64,  0,128, 64); }
    sub SetGraphicLeft  { SetGraphicRect(128,  0,192, 64); }
    sub SetGraphicRight { SetGraphicRect(192,  0,256, 64); }

    sub SetGraphicMove {
	if(GetSpeedX <  0) { SetGraphicLeft(); }
	else { SetGraphicRight(); }
    }

    // w t[ҋ@
    function wait(w) { loop(w){ yield; } }

}